package com.gome.axwl.aoc.entity.enums;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * @Description: 业务枚举类(多处在引用 修改删除需谨慎)
 * @Auther: yinyuxin@gome.com.cn
 * @Date: 2018/7/17 20:40
 */
public enum  BusinessEnum {



    /*******************************审批类型（approval_type）************************************/

    APPROVAL_TYPE_CS_OPERATION ("1","服务商入驻审核","approval_type"),

    /*******************************审批状态（approval_status）************************************/

    APPROVAL_STATUS_PENDING ("0","拒绝","approval_status"),

    APPROVAL_STATUS_APPROVALED ("1","同意","approval_status"),

    APPROVAL_STATUS_CHANGE ("2","转移","approval_status"),

    /*******************************服务商入驻文件类型（carrier_settle_FILE_type）************************************/

    CARRIER_SETTLE_FILE_TYPE_BASICINFO("cs_basic_info","服务商入驻--身份证照片","carrier_settle_img_type"),

    CARRIER_SETTLE_FILE_TYPE_LICENSE("cs_license_info","服务商入驻--营业执照照片","carrier_settle_img_type"),

    CARRIER_SETTLE_FILE_TYPE_ATTACHMENT("cs_attachment_info","服务商入驻--附件","carrier_settle_img_type"),

    /*******************************服务商入驻业务类型（cs_server_type）************************************/

    CARRIER_SETTLE_SERVER_TYPE_GROUND("cs_server_ground","干线运输","cs_server_type"),
    CARRIER_SETTLE_SERVER_TYPE_CITY("cs_server_city","城市运输","cs_server_type"),
    CARRIER_SETTLE_SERVER_TYPE_INSTALL("cs_server_install","安装","cs_server_type"),

    /*******************************服务商入驻业务类型（cs_approval_status）************************************/

    CARRIER_SETTLE_APPROVAL_STATUS__DRA("0","草稿","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_OP("4","运营待审核","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_OF("5","运营审核未通过","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_FP("6","财务待审核","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_FFQ("7","审核未通过:资质","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_FFA("8","审核未通过:附件","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_SP("9","服务商待签","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_SPED("10","服务商已签","cs_approval_status"),
    CARRIER_SETTLE_APPROVAL_STATUS_SS("11","服务商入驻成功","cs_approval_status"),

    /*******************************服务商入驻单审批类型（cs_approval_type）************************************/

    CARRIER_SETTLE_APPROVAL_TYPE_DEFAULT("0","默认运营审核单","cs_approval_type"),
    CARRIER_SETTLE_APPROVAL_TYPE_SPECIAL("1","指定运营审核单","cs_approval_type"),
    CARRIER_SETTLE_APPROVAL_TYPE_TRANSFER("2","运营审核转移单","cs_approval_type"),

    /*******************************服务商入驻单审批类型（cs_approval_user_type）************************************/

    CARRIER_SETTLE_APPROVAL_USER_TYPE_FINANCI("1","默认财务审核权","cs_approval_user_type"),
    CARRIER_SETTLE_APPROVAL_USER_TYPE_BUSINESS("2","默认运营审核权","cs_approval_user_type"),
    CARRIER_SETTLE_APPROVAL_USER_TYPE_FORMAL("3","一般审核权","cs_approval_user_type"),



    TEST_DEFAULT("test","test","test");

    private String itemCode;

    private String itemName;

    private String itemType;

    BusinessEnum(String itemCode, String itemName, String itemType) {
        this.itemCode = itemCode;
        this.itemName = itemName;
        this.itemType = itemType;
    }

    public String getItemCode() {
        return itemCode;
    }

    public void setItemCode(String itemCode) {
        this.itemCode = itemCode;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getItemType() {
        return itemType;
    }

    public void setItemType(String itemType) {
        this.itemType = itemType;
    }

    /**
     * 枚举转list，类似于数据字典
     * @param itemType
     * @return
     */
    public static List<BusinessEnumDto> businessEnum2List(String itemType){
        if (StringUtils.isBlank(itemType)){
            return null;
        }
        List<BusinessEnumDto> data=new ArrayList<>();
        for (BusinessEnum businessEnum:BusinessEnum.values()){
            if (StringUtils.equals(itemType,businessEnum.getItemType())){
                BusinessEnumDto businessEnumDto=new BusinessEnumDto();
                businessEnumDto.setItemCode(businessEnum.itemCode);
                businessEnumDto.setItemName(businessEnum.itemName);
                if (businessEnum == BusinessEnum.CARRIER_SETTLE_APPROVAL_STATUS__DRA) {//草稿不返回
                    continue;
                }
                data.add(businessEnumDto);
            }
        }
        return data;
    }

    /**
     * 通过编码和类型查询值
     * @param itemCode
     * @param itemType
     * @return
     */
    public static String queryNameByItemCodeAndType(String itemCode,String itemType){
        if (StringUtils.isBlank(itemCode)){
            return null;
        }
        List<BusinessEnumDto> data=new ArrayList<>();
        for (BusinessEnum businessEnum:BusinessEnum.values()){
            if (StringUtils.equals(itemCode,businessEnum.getItemCode())&&StringUtils.equals(itemType,businessEnum.getItemType())){
                BusinessEnumDto businessEnumDto=new BusinessEnumDto();
                businessEnumDto.setItemCode(businessEnum.itemCode);
                businessEnumDto.setItemName(businessEnum.itemName);
                data.add(businessEnumDto);
            }
        }
        return (data!=null && data.size()>0)?data.get(0).getItemName():null;
    }
}
